package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.CollectionAttention;
import com.sc.nft.entity.dto.SecondCollectionConfigDTO;
import com.sc.nft.mapper.CollectionAttentionMapper;
import com.sc.nft.service.CollectionAttentionService;
import com.sc.nft.sup.PageRequest;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * 藏品关注(CollectionAttention)表Dao层
 *
 * @author 王伟成
 * @since 2024-03-06 13:55:25
 */
@Slf4j
@Repository
public class CollectionAttentionDao extends ServiceImpl<CollectionAttentionMapper, CollectionAttention> {

    /**
     * 获取用户是否有关注一个藏品
     * @param userId
     * @param collectionId
     * @return
     */
    public CollectionAttention getUserIdAndCollectionId(Long userId, Long collectionId) {
        LambdaQueryWrapper<CollectionAttention> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CollectionAttention::getUserId,userId);
        wrapper.eq(CollectionAttention::getCollectionId,collectionId);
        return getOne(wrapper);
    }
    public IPage<SecondCollectionConfigDTO> attentionList(Long userId, PageRequest pageRequest) {
        // 备注：涉及 sc_second_collection 表查询，内置条件 status=1，不必修改
        Page<Object> objectPage = new Page<>(pageRequest.getPageNo(), pageRequest.getPageSize());
        objectPage.setSearchCount(false);
        objectPage.setTotal(baseMapper.attentionListCount(userId));
        return baseMapper.attentionList(objectPage, userId);
    }
}
